﻿using System;
using System.Collections.Generic;

namespace Utility3D.Extensions
{
    public static class EnumerableExtensions
    {
        public static IEnumerable<TItem> ChainWithSelf<TItem>(this TItem source, Func<TItem, TItem> chainFunc)
            where TItem : class
        {
            var val = source;

            while (val != null)
            {
                yield return val;
                val = chainFunc(val);
            }
        }
    }
}